/**
 * 
 */
package Consult.view;

import java.awt.EventQueue;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;

import javax.swing.JInternalFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import Consult.model.BookType;
import Util.DbCUtil;

/**
 * @author zhaoyana
 *
 */
public class InterTypeManagerFrame extends JInternalFrame {
	private JTable booktypeTable;
    private DbCUtil dbUtil=new DbCUtil();
    private BookTypeDao booktypeDao=new BookTypeDao();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					InterTypeManagerFrame frame = new InterTypeManagerFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public InterTypeManagerFrame() {
		setIconifiable(true);
		setClosable(true);
		setBounds(100, 100, 711, 559);
		
		JScrollPane scrollPane = new JScrollPane();
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(66)
					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 573, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(56, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(32)
					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 363, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(128, Short.MAX_VALUE))
		);
		
		booktypeTable = new JTable();
		booktypeTable.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"\u56FE\u4E66\u7C7B\u522B\u6807\u53F7", "\u56FE\u4E66\u7C7B\u522B\u540D\u79F0", "\u56FE\u4E66\u7C7B\u522B\u63CF\u8FF0"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				false, false, false
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		scrollPane.setViewportView(booktypeTable);
		getContentPane().setLayout(groupLayout);
     this.fillTable(new BookType());

	}
	
/**
 * 初始化表格
 * @param booktype
 */
	private void fillTable(BookType booktype) {
		DefaultTableModel d=(DefaultTableModel)booktypeTable.getModel();
		d.setRowCount(0);//清空表格
		Connection con=null;
		try {
			con=DbCUtil.getCon();
			ResultSet rs=booktypeDao.list(con, booktype);
			while(rs.next()) {
				Vector v=new Vector();
				v.add(rs.getString("id"));
				v.add(rs.getString("booktypeName"));
				v.add(rs.getString("bookTypeDesc"));//定义集合
				d.addRow(v);
			}
		}catch(Exception e) {
			e.printStackTrace();
			
		}finally {
			try {
				DbCUtil.closeCon(con);
			}catch (Exception e) {
      e.printStackTrace();
		}
	}
	
	}
	}
